package com.oocl.pmsystem.bean.comparator.impl;

import com.oocl.pmsystem.bean.Person;
import com.oocl.pmsystem.bean.comparator.SuperComparator;

/**
 * 账户姓名比较器
 * @author WUJA13
 *
 */
public class PersonNameComparator implements SuperComparator<Person> {

	public int compare(Person o1, Person o2) {
		return compareString(o1.getName(), o2.getName());
	}

	///两个char[] 的比较
	private int compareString(String o1, String o2) {
		char[] v1 = o1.toCharArray();
		char[] v2 = o2.toCharArray();
		int len1 = v1.length;
		int len2 = v2.length;
		int lim = Math.min(len1, len2);
		int k = 0;
		while (k < lim) {
			char c1 = v1[k];
			char c2 = v2[k];
			if (c1 != c2) {
				return c1 - c2;
			}
			k++;
		}
		return len1 - len2;
	}
}
